﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using Utilities;

namespace SkypeApp
{
    public partial class SkypeBar : Form, SkypeApp.ISkypeBar
    {
        SkypeBarController controller;

        public void Clear()
        {
            flowLayoutPanel1.Controls.Clear();
            this.Text = "Скайп не подключен ";
        }

        public SkypeBar()
        {
            InitializeComponent();
            controller = new SkypeBarController(this);
            this.Disposed += new EventHandler(SkypeBar_Disposed);
        }

        void SkypeBar_Disposed(object sender, EventArgs e)
        {
            controller.Dispose();
        }

        protected override void OnFormClosed(FormClosedEventArgs e)
        {
            base.OnFormClosed(e);
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.SetDesktopLocation(0, 0);
            controller.Start();
        }

        void CallToFriendClicked(object sender, EventArgs e)
        {
            controller.OnFriendClicked(((SkypeUser)sender).User.Handle);
        }

        public void ShowUsers(IList<DisplayUser> users)
        {
            flowLayoutPanel1.Controls.Clear();
            this.Text = "Подключен к Скайп";
            foreach (var user in users)
            {
                SkypeUser control = new SkypeUser() { User = user };
                control.ButtonClicked += new EventHandler(CallToFriendClicked);
                flowLayoutPanel1.Controls.Add(control);
            }
        }

        void ISkypeBar.Focus()
        {
            this.Focus();
        }
    }
}

